from bs4 import BeautifulSoup

html = '''
    <html>
        <head>
            <title>测试美味的Soup</title>
        </head>
        <body>
            <div id="d1">测试d1</div>
            <div id="d2">测试d2</div>
            <ul id="ut">
                <li>测试列表01</li>
                <li>测试列表02</li>
                <li>测试列表03</li>
                <li>测试列表04</li>
                <li>测试列表05</li>
                <li>测试列表06</li>
            </ul>
            
            <ul>
                <li class="ti">再次测试列表01</li>
                <li class="ti">再次测试列表02</li>
                <li class="ti">再次测试列表03</li>
                <li class="ti">再次测试列表04</li>
                <li class="ti">再次测试列表05</li>
                <li class="ti">再次测试列表06</li>
            </ul>
        </body>
    </html>
'''

#使用了html的parser
bs = BeautifulSoup(html,'lxml')
print(bs.title)

print(bs.select("li.ti"))
for item in bs.select("li.ti"):
    print(item.text,item.get('class'))

print(bs.select("#ut li:nth-child(even)"))

print(bs.select("li"))
print(bs.select("#d1,#d2"))